package com.fh.type.controller;/**
 * 描述:
 * Author:袁亚强
 * Date:2022/1/610:12
 */

import com.fh.type.entity.ShopType;
import com.fh.type.service.ShopService;
import com.fh.type.utils.FullData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * created by macro on 2022/1/6,
 */
@RestController
@RequestMapping("type")
public class ShopTypeController {
    @Autowired
    private ShopService shopService;

    @PostMapping("addShopType")
    public FullData addShopType(ShopType shopType) {
        if (shopType.getPid() == null) {
            return FullData.error(400, "缺少参数");
        }
        if (StringUtils.isEmpty(shopType.getName())) {
            return FullData.error(400, "缺少参数");
        }
        shopService.addShopType(shopType);
        this.reflushType();
        return FullData.success("");
    }

    @PostMapping("upOrDel")
    public FullData upOrDel(ShopType shopType) {
        if (shopType.getId() == null) {
            return FullData.error(400, "缺少参数");
        }
        shopService.upOrDel(shopType);
        this.reflushType();
        return FullData.success("");
    }

    @GetMapping("reflushType")
    public FullData reflushType(){
        shopService.reflushType();
        return FullData.success("");
    }

    @GetMapping("queryType")
    public FullData queryType() {
        return FullData.success(shopService.query());
    }


}
